package com.wds.controller;


import com.wds.domain.JsonResult;
import com.wds.domain.entity.Tag;
import com.wds.domain.vo.TagListVoVo;
import com.wds.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标签(Tag)控制层
 *
 * @author wds
 * @since 2022-12-05 11:51:36
 */
@RestController
@RequestMapping("/content/tag")
public class TagController {

    // 服务对象
    @Autowired
    private TagService tagService;

    @GetMapping("/list")
    public JsonResult<TagListVoVo> queryList(int pageNum, int pageSize, String name) {
        //页面大小限制
        if (pageSize > 30) {
            pageSize = 30;
        }

        return tagService.pageList(pageNum, pageSize, name);
    }

    @GetMapping("/listAllTag")
    public JsonResult<List<Tag>> queryAll() {
        return tagService.queryAll();
    }

    @PostMapping
    public JsonResult<Object> addNewTag(@RequestBody Tag tag) {
        return tagService.addNewTag(tag);
    }

    @DeleteMapping("/{ids}")
    public JsonResult<Object> delete(@PathVariable List<Long> ids) {
        return tagService.delete(ids);
    }

    @GetMapping("/{id}")
    public JsonResult<Object> queryById(@PathVariable String id) {
        return tagService.queryById(id);
    }

    @PutMapping()
    public JsonResult<Object> updateTag(@RequestBody Tag tag){
        return tagService.updateTag(tag);
    }

}

